<?php 
require_once "class.db.php";
class trangchu extends db{	
	/* SAN PHAM */
	function getDetailSP($sp_id){
		$sql= "SELECT * 
			FROM sanpham
			WHERE sp_id = $sp_id";
		$rs= mysql_query($sql) or die(mysql_error());
		return $rs;
	}	
        function getDetailSP1($idSP){
		$sql= "SELECT * 
			FROM sanpham
			WHERE sp_id = $idSP";
		$rs= mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getListChatLieu($lang='vi'){
		$sql = "SELECT * FROM chatlieu ORDER BY chat_id ASC ";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getListKieuDang(){
		$sql = "SELECT * FROM kieu ORDER BY kieu_id ASC  ";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getListMau(){
		$sql = "SELECT * FROM mau ORDER BY mau_id ASC ";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getListMauByProductId($sp_id){
		$sql = "SELECT mau_id FROM sp_mau where sp_id = $sp_id ORDER BY mau_id ASC  ";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getDetailMau($mau_id){
		$sql = "SELECT * FROM mau WHERE mau_id =$mau_id ";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getListSizeByProductId($sp_id){
		$sql = "SELECT size_id FROM sp_size where sp_id = $sp_id ORDER BY size_id ASC  ";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getDetailSize($size_id){
		$sql = "SELECT * FROM size WHERE size_id =$size_id ";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getTagsByProductId($sp_id){
		$sql = "SELECT tag_id FROM sp_tag WHERE sp_id = $sp_id";
		$rs = mysql_query($sql);
		return $rs;
	}
	function getDetailTag($tag_id){
		$sql = "SELECT * FROM tag WHERE tag_id = $tag_id";
		$rs = mysql_query($sql);
		return $rs;
	}
	function getContentDetailPage($id){
		$sql = "SELECT * FROM menu WHERE idMenu = $id";
		$rs = mysql_query($sql);
		$row = mysql_fetch_assoc($rs);
		return $row['noidung']; 
	}        
        function sanphammoi(){
                $sql= "SELECT * 
			FROM sanpham
			ORDER BY sp_id DESC LIMIT 0,8";
		$rs= mysql_query($sql) or die(mysql_error());
		return $rs;
        }
        function sanpham_theoloai($loai_id){
            $sql = "SELECT * FROM sanpham WHERE loai_id = $loai_id ORDER BY sp_id DESC";
            $listSP = mysql_query($sql) or die(mysql_error());
            return $listSP;
        }
        function sanpham_cothethich($loai_id){
            $sql = "SELECT * FROM sanpham WHERE loai_id = $loai_id ORDER BY RAND() DESC limit 0,3";
            
            $listSP = mysql_query($sql) or die(mysql_error());
            return $listSP;
        }
        function getTenLoai($idloai){
            $sql = "SELECT * FROM loaisp WHERE loai_id = $idloai";
            $listSP = mysql_query($sql) or die(mysql_error());
            return $listSP;
        }
        function sanpham_theokieu($kieuid){
            $sql = "SELECT * FROM sanpham WHERE kieu_id = $kieuid  Limit 0,3";
            $listSP = mysql_query($sql) or die(mysql_error());
            return $listSP;
        }
        function getListKhoangGia() {
            $sql = "SELECT * FROM khoanggia ORDER BY thutu ASC  ";
            $rs = mysql_query($sql) or die(mysql_error());
            return $rs;
        }
        function checksp_trongkhoanggia($loai_id,$kg_id){
            $sql = "SELECT sp_id FROM sanpham WHERE loai_id = $loai_id AND kg_id = $kg_id";
            $rs = mysql_query($sql) or die(mysql_error());
            $sosp = mysql_num_rows($rs);
            return $sosp;
        }
        function checksp_theokieu($loai_id,$kieu_id){
            $sql = "SELECT sp_id FROM sp_kieu WHERE kieu_id = $kieu_id";
            $rs = mysql_query($sql) or die(mysql_error());
            $sosp = mysql_num_rows($rs);
            return $sosp;
        }
        function checksp_theomau($loai_id,$mau_id){
            $sql = "SELECT sp_id FROM sp_mau WHERE loai_id = $loai_id AND mau_id = $mau_id";
            $rs = mysql_query($sql) or die(mysql_error());
            $sosp = mysql_num_rows($rs);
            return $sosp;
        }
        function detail_loaisp($loai_id){
            $sql = "SELECT * FROM loaisp WHERE loai_id = $loai_id";
            $rs = mysql_query($sql) or die(mysql_error());
            return $rs;
        }
        function listkieudang_byloai($loai_id){
            $sql = "SELECT * FROM kieu WHERE loai_id = $loai_id ORDER BY kieu_id ASC  ";
            $rs = mysql_query($sql) or die(mysql_error());
            return $rs;
        }
        
        
}

?>